package com.jxwifi.cloud.quickclean.mycenter;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.basicactivity.BasicActivity;
import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.MainActivity;
import com.jxwifi.cloud.quickclean.app.AccountMgr;
import com.jxwifi.cloud.quickclean.app.ClientBasicActivity;
import com.jxwifi.cloud.quickclean.app.PasswordLogin;
import com.jxwifi.cloud.quickclean.utils.TitleClient;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.utils.ToastUtils;
import com.umeng.analytics.MobclickAgent;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置手机号码
 * Created by Administrator on 2019/6/19.
 */

public class SetPhoneActivity extends ClientBasicActivity implements SetPhoneView {

    @Bind(R.id.et_set_phone)
    EditText mEtSetPhone;
    @Bind(R.id.et_set_phone_verification)
    EditText mEtSetPhoneVerification;
    @Bind(R.id.tv_obtain_verification)
    TextView mTvObtainVerification;
    private SetPhonePresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_phone);
        ButterKnife.bind(this);
        openEventBus();
        mPresenter = new SetPhonePresenter(mBaseContext, this);
        initHead();
        initView();
    }

    private void initHead() {
        TitleClient holder = new TitleClient(ButterKnife.findById(this, R.id.lin_client_title));
        holder.defineTitle("设置新手机号码");
        holder.defineLeft(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onBackPressed();
            }
        });
        holder.defineTextRight("保存", new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPresenter.judge();
                MobclickAgent.onEvent(mBaseContext, "phone_preservation");
            }
        });
    }

    public void initView() {

    }

    @OnClick({R.id.tv_obtain_verification})
    void clickCK(View v) {
        switch (v.getId()) {
            case R.id.tv_obtain_verification:
                mPresenter.validation();
                break;
        }
    }

    @Override
    public EditText getPhone() {
        return mEtSetPhone;
    }

    @Override
    public EditText getPhoneVerification() {
        return mEtSetPhoneVerification;
    }

    @Override
    public TextView getObtainVerification() {
        return mTvObtainVerification;
    }

    @Override
    public void onFailure(int errorCode, String msg) {
        Toast toast = Toast.makeText(mBaseContext, msg, Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
    }

    @Override
    public void onSuccess() {
        Toast toast = Toast.makeText(mBaseContext, "设置成功", Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
        Intent intent = new Intent();
        intent.setClass(mBaseContext, MainActivity.class);
        finish();
    }

    @Override
    public void onlogining() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.logining();
        }
    }
}
